<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var consecutive = function (n) {
      let ans = 0;
      for (let k = 1; k * (k + 1) <= 2 * n; k++) {
        if (isKConsecutive(n, k)) {
          ans++;
        }
      }
      return ans;
    }

    const isKConsecutive = (n, k) => {
      if (k % 2 === 1) {
        return n % k === 0;
      } else {
        return n % k !== 0 && 2 * n % k === 0;
      }
    };
    console.log(consecutive(n = 9))
  </script>
</body>

</html>